﻿package framework.core;

import java.util.*;
/**
 * @author Administrator
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class XmlUtil 
{
	private Vector m_values = new Vector();
	
	public static void postXml(SrvContext context,String[] objs) throws Exception
	{
		String s =  "<Objects>";
		for(int i=0;i<objs.length;i++)
		{
			s += objs[i];
		}
		s += "</Objects>";
		postXml(context,s);
	}
	public static void postXml(SrvContext context,String xml) throws Exception
	{
		String xmlPath = Config.getXmlJspPath();
		context.setValue("XmlObject",xml);
		context.setAbsPath(true);
		context.setNextUrl(xmlPath);
	}
	
	public void addXmlValue(String name,String value) throws Exception 
	{
		NamedValue v = new NamedValue(name,value);
		m_values.add(v);
	}
	public void post(SrvContext context) throws Exception
	{
		String xml = "";
		xml += "<XmlObject>";
		for(int i=0;i<m_values.size();i++)
		{
			NamedValue v = (NamedValue)m_values.get(i);
			xml += "<"+v.getName()+">"+v.getString()+"</"+v.getName()+">";
		}
		xml += "</XmlObject>";
		postXml(context,xml);
	}
	
	public String getXmlString() throws Exception
	{
		String xml = "";
		xml += "<order>";
		for(int i=0;i<m_values.size();i++)
		{
			NamedValue v = (NamedValue)m_values.get(i);
			xml += "<"+v.getName()+">"+v.getString()+"</"+v.getName()+">";
		}
		xml += "</order>";
		
		return xml;
	}
	
	public static void postNull(SrvContext context) throws Exception
	{
		postXml(context,"null");
	}
		
}
